﻿using System.Collections.Generic;
using System.Xml.Serialization;

namespace Inkubator.Wizard.Model.Model
{
    /// <summary>
    /// Layout Class represent how the different component of the wizard
    /// will be display in the web page.
    /// </summary>
    [XmlRoot("layout")]
    public class Layout
    {
        /// <summary>
        /// List of Text components.
        /// </summary>
        private List<Text> texts;
        /// <summary>
        /// List of Group components.
        /// </summary>
        private List<Group> groups;
        /// <summary>
        /// List of Table components.
        /// </summary>
        private List<TableData> tables;
        /// <summary>
        /// List of Date components.
        /// </summary>
        private List<Date> dates;

        public Layout() {
            texts = new List<Text>();
            groups = new List<Group>();
            tables = new List<TableData>();
            dates = new List<Date>();
        }

        public Layout(List<Text> text, List<Group> group, List<Date> date, List<TableData> table)
        {
            this.texts = text;
            this.groups = group;
            this.dates = date;
            this.tables = table;
        }

        [XmlElement("text")]
        public Text[] textArray
        {
            get
            {
                Text[] textArray = new Text[this.texts.Count];
                texts.CopyTo(textArray);
                return textArray;
            }
            set
            {
                if (value == null) return;
                Text[] textArray = (Text[])value;
                texts.Clear();
                foreach (Text text in textArray)
                    texts.Add(text);
            }
        }

        [XmlElement("group")]
        public Group[] groupArray
        {
            get
            {
                Group[] groupArray = new Group[this.groups.Count];
                groups.CopyTo(groupArray);
                return groupArray;
            }
            set
            {
                if (value == null) return;
                Group[] groupArray = (Group[])value;
                groups.Clear();
                foreach (Group group in groupArray)
                    groups.Add(group);
            }
        }

        [XmlElement("table")]
        public TableData[] tableArray
        {
            get
            {
                TableData[] tableArray = new TableData[this.tables.Count];
                tables.CopyTo(tableArray);
                return tableArray;
            }
            set
            {
                if (value == null) return;
                TableData[] tableArray = (TableData[])value;
                tables.Clear();
                foreach (TableData table in tableArray)
                    tables.Add(table);
            }
        }

        [XmlElement("date")]
        public Date[] dateArray
        {
            get
            {
                Date[] dateArray = new Date[this.dates.Count];
                dates.CopyTo(dateArray);
                return dateArray;
            }
            set
            {
                if (value == null) return;
                Date[] dateArray = (Date[])value;
                dates.Clear();
                foreach (Date date in dateArray)
                    dates.Add(date);
            }
        }

        /// <summary>
        /// Add a Text Component to the Texts List
        /// </summary>
        /// <param name="text"></param>
        public void AddText(Text text)
        {
            texts.Add(text);
        }

        /// <summary>
        /// Add a Group Component to the Groups List
        /// </summary>
        /// <param name="group"></param>
        public void AddGroup(Group group)
        {
            groups.Add(group);
        }

        /// <summary>
        /// Add a Table Component to the Tables List
        /// </summary>
        /// <param name="table"></param>
        public void AddTable(TableData table)
        {
            tables.Add(table);
        }

        /// <summary>
        /// Add a Date Component to the Dates List
        /// </summary>
        /// <param name="date"></param>
        public void AddDate(Date date)
        {
            dates.Add(date);
        }

    }
}
